﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
namespace WebUI.Services
{
    /// <summary>
    /// GlobalAppVariable 的摘要说明
    /// </summary>
    public class GlobalAppVariable : IHttpHandler, System.Web.SessionState.IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            switch (context.Request["action"])
            {
                case "setusersession":
                    context.Response.Write(SetUserSession(context,context.Request.QueryString["username"]));
                    context.Response.End();
                    break;
                case "logout":
                    LogOut();
                    context.Response.End();
                    break;
            }
        }

        private string SetUserSession(HttpContext context, string user)
        {
            context.Session["myaspxuser"] = user;
            if (context.Session["myaspxuser"] != null)
            {
                return "ok";
            }
            else
            {
                return "fail";
            }
        }

        private void LogOut()
        {
            HttpContext.Current.Session["myaspxuser"] = null;
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}